home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / IM_3 .adf / Exec / piarc.LZH / raw.rexx < prev    next >
OS/2 REXX Batch file  |  1992-02-29  |  9KB  |  369 lines

  1. /* */
  2. parse arg var1
  3. /*
  4.  * RAW.rexx
  5.  *
  6.  *  Written by: Barry Chalmers & Ben Williams
  7.  * Last Update: March 4th, 1992
  8.  *    Revision: 1.03
  9.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  10.  */
  11.  
  12. /*
  13.  * open rexxsupport.library -- needed for some functions
  14.  */
  15. if ~show('L',"rexxsupport.library") then do
  16.   if addlib('rexxsupport.library',0,-30,0) then do
  17.       /* everything's ok */
  18.     end;
  19.   else do
  20.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  21.     say 'Cannot operate RAW.rexx without this library - sorry!';
  22.     exit 10;
  23.     end;
  24.   end;
  25. /*
  26.  * This will automatically direct the script to the proper
  27.  * software, if it is running. No matter where the script is
  28.  * launched from. :^) I sure do like ARexx. :^))
  29.  */
  30. prtnme = 'IP_Port'; /* assume Image Professional */
  31. if show('P','IP_Port') = 0 then do
  32.   if show('P','IM_Port') = 0 then do
  33.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  34.     say "This script requires IP, IM or IM F/c to run!";
  35.     exit(20);
  36.     end;
  37.   else do
  38.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  39.     end;                 /* We make em, user's break em.          */
  40.   end;
  41.  
  42.   /*
  43.    * This code attempts to read a file called "picmdpath" from REXX:
  44.    * If it can't find it, the script will assume that the commands
  45.    * associated with this PI Module are in "c:". If the file exists,
  46.    * the script will look in the path that is specified in the file.
  47.    * If you create this file, you MUST put a complete, correct path
  48.    * in it; if the commands are in a sub-directory, you have to put
  49.    * the trailing slash on the path (like, device:dir/).
  50.    * 
  51.    */
  52.   cmdpath = 'c:';
  53.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  54.     do
  55.       cmdpath = readln(fhandle);
  56.       call close(fhandle);  /* close the file    */
  57.     end
  58.  
  59. /*
  60.  * Get the file name parts
  61.  */
  62.   prevpath = 'ram:';
  63.   if show('C',rawpath) = 1 then do
  64.     prevpath = getclip(rawpath);
  65.     end;
  66.   prevname = 'image';
  67.   if show('C',rawname) = 1 then do
  68.     prevname = getclip(rawname);
  69.     end;
  70.   prevext = '.red';
  71.   if show('C',rawext) = 1 then do
  72.     prevext = getclip(rawext);
  73.     end;
  74.   width = 320;
  75.   if show('C',rawwidth) = 1 then do
  76.     width = getclip(rawwidth);
  77.     end;
  78.   height = 200;
  79.   if show('C',rawheight) = 1 then do
  80.     height = getclip(rawheight);
  81.     end;
  82.  
  83. address(prtnme);
  84.  
  85. 'tofront';
  86.  
  87. if var1 = 'load' then do
  88.   loadquestion = 0
  89.   end
  90. else if var1 = 'save' then do
  91.   loadquestion = 1
  92.   end
  93. else do
  94.   options results;
  95.   'gadgets "Load Raw","Files","Save Raw","Files"';
  96.   loadquestion = result-1;
  97.   options;
  98.   end
  99.  
  100. if loadquestion < 0 then do
  101.   address(prtnme);
  102.   'tofront';
  103.   exit 0;
  104.   end
  105.  
  106. if loadquestion = 0 then do
  107.  
  108.   options results;
  109.   'gadgets "Load one file","as B/W","Load three files","(R-G-B)"';
  110.   threefiles = result-1;
  111.   options;
  112.   if threefiles < 0 then do
  113.     address(prtnme);
  114.     'tofront';
  115.     exit 0;
  116.     end
  117.  
  118.   if threefiles = 0 then do
  119.     prevext = '';
  120.     options results;
  121.     'filerequest "'||prevpath||'" "'||prevname||'" "'||prevext||'" '||'"Load B/W"';
  122.     redfile = result;
  123.     options;
  124.     call checkfile(redfile);
  125.     
  126.     options results;
  127.     'asknumber "Width (X)","'||width;
  128.     width = result;
  129.     options;
  130.     call setclip(rawwidth,width);
  131.     
  132.     options results;
  133.     'asknumber "Height (Y)","'||height;
  134.     height = result;
  135.     options;
  136.     call setclip(rawheight,height);
  137.  
  138.     'autoredraw 0';
  139.     'newasprimary '||width||' '||height;
  140.     options results;
  141.     'jackin';
  142.     jack = result;
  143.     options;
  144.  
  145.     'tofront';
  146.     address command cmdpath||'rdraw '||jack||' '||width||' '||height||' '||redfile;
  147.     address(prtnme);
  148.     end
  149.   else do
  150.     prevext = '.red';
  151.     options results;
  152.     'filerequest "'||prevpath||'" "'||prevname||'" "'||prevext||'" '||'"Load Red"';
  153.     redfile = result;
  154.     options;
  155.     call checkfile(redfile);
  156.     
  157.     prevext = '.grn';
  158.     options results;
  159.     'filerequest "'||prevpath||'" "'||prevname||'" "'||prevext||'" '||'"Load Green"';
  160.     greenfile = result;
  161.     options;
  162.     call checkfile(greenfile);
  163.     
  164.     prevext = '.blu';
  165.     options results;
  166.     'filerequest "'||prevpath||'" "'||prevname||'" "'||prevext||'" '||'"Load Blue"';
  167.     bluefile = result;
  168.     options;
  169.     call checkfile(bluefile);
  170.     
  171.     options results;
  172.     'asknumber "Width (X)","'||width;
  173.     width = result;
  174.     options;
  175.     call setclip(rawwidth,width);
  176.     
  177.     options results;
  178.     'asknumber "Height (Y)","'||height;
  179.     height = result;
  180.     options;
  181.     call setclip(rawheight,height);
  182.  
  183.     'autoredraw 0';
  184.     options results;
  185.     'newasprimary '||width||' '||height;
  186.     if rc ~= 0 then do
  187.       "message Can't allocate buffer!";
  188.       'autoredraw 1';
  189.       exit 0;
  190.       end
  191.     bnum = result;
  192.     'jackin';
  193.     jack = result;
  194.     options;
  195.  
  196.     'tofront';
  197.     'lockimage '||bnum;
  198.     address command cmdpath||'rdraw '||jack||' '||width||' '||height||' '||redfile||' '||greenfile||' '||bluefile;
  199.     'unlockimage '||bnum;
  200.     address(prtnme);
  201.     end
  202.   end
  203. else do
  204.  
  205.   options results;
  206.   'gadgets "Save one file","as B/W","Save three files","(R-G-B)"';
  207.   threefiles = result - 1;
  208.   options;
  209.   if threefiles < 0 then do
  210.     address(prtnme);
  211.     'tofront';
  212.     exit 0;
  213.     end
  214.  
  215.   if threefiles = 0 then do
  216.     prevext = '.bw';
  217.     options results;
  218.     'filerequest "'||prevpath||'" "'||prevname||'" "'||prevext||'" '||'"Save B/W"';
  219.     redfile = result;
  220.     options;
  221.     call checkfile(redfile);
  222.  
  223.     options results;
  224.     'jackin';
  225.     jack = result;
  226.     options;
  227.  
  228.     'tofront';
  229.     address command cmdpath||'wrraw '||jack||' '||redfile;
  230.     address(prtnme);
  231.     end
  232.   else do
  233.     prevext = '.red';
  234.     options results;
  235.     'filerequest "'||prevpath||'" "'||prevname||'" "'||prevext||'" '||'"Save Red"';
  236.     redfile = result;
  237.     options;
  238.     call checkfile(redfile);
  239.     
  240.     prevext = '.grn';
  241.     options results;
  242.     'filerequest "'||prevpath||'" "'||prevname||'" "'||prevext||'" '||'"Save Green"';
  243.     greenfile = result;
  244.     options;
  245.     call checkfile(greenfile);
  246.     
  247.     prevext = '.blu';
  248.     options results;
  249.     'filerequest "'||prevpath||'" "'||prevname||'" "'||prevext||'" '||'"Save Blue"';
  250.     bluefile = result;
  251.     options;
  252.     call checkfile(bluefile);
  253.     
  254.     options results;
  255.     'jackin';
  256.     jack = result;
  257.     options;
  258.     
  259.     'tofront';
  260.     address command cmdpath||'wrraw '||jack||' '||redfile||' '||greenfile||' '||bluefile;
  261.     address(prtnme);
  262.     end
  263.   end
  264.  
  265. 'autoredraw 1';
  266. 'tofront';
  267. if loadquestion = 0 then do
  268.    address(prtnme);
  269.   'redraw';
  270.   end
  271.  
  272. exit 0;
  273.  
  274. checkfile: 
  275. arg thefile;
  276.   if thefile = 'FR_CANCELLED' then do
  277.     address(prtnme);
  278.     'tofront';
  279.     exit 0;
  280.     end;
  281.   prevpath = gimmepath(thefile);
  282.   call setclip(rawpath,prevpath);
  283.   prevname = gimmename(thefile);
  284.   call setclip(rawname,prevname);
  285.   prevext  = gimmeext(thefile);
  286.   call setclip(rawext,prevext);
  287.   return;
  288.   end
  289.  
  290. /*
  291.  * gimmepath
  292.  *
  293.  * This takes the provided argument and sucks the path out of it, then
  294.  * returns that path to the caller, sans file name.
  295.  */
  296. gimmepath:
  297.   arg fullnamegx;
  298.     tempgx = reverse(fullnamegx);
  299.     lengx = length(fullnamegx);   /* get length of string */
  300.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  301.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  302.     seploc = 0; /* assumes current dir, no path supplied */
  303.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  304.       seploc = (lengx - slashdex)+1;
  305.       end;
  306.     else do
  307.       if colondex ~= 0 then do /* we assume we are on a device */
  308.         seploc = (lengx - colondex)+1;
  309.         end;
  310.       end;
  311.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  312.   gxpath = left(fullnamegx,seploc);
  313.   return(gxpath);
  314.   end
  315.  
  316.  
  317. gimmename:
  318.   arg fullnamegx;
  319.     tempgx = reverse(fullnamegx);
  320.     lengx = length(fullnamegx);   /* get length of string */
  321.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  322.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  323.     seploc = 0; /* assumes current dir, no path supplied */
  324.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  325.       seploc = (lengx - slashdex)+1;
  326.       end;
  327.     else do
  328.       if colondex ~= 0 then do /* we assume we are on a device */
  329.         seploc = (lengx - colondex)+1;
  330.         end;
  331.       end;
  332.   extpos = lastpos(".",fullnamegx) - 2;
  333.   if extpos > seploc then do
  334.     gxname = substr(fullnamegx,seploc+1,extpos-seploc+1);
  335.     end;
  336.   else do
  337.     gxname = substr(fullnamegx,seploc+1);
  338.     end;
  339.   return(gxname);
  340.   end
  341.  
  342.  
  343. gimmeext:
  344.   arg fullnamegx;
  345.     tempgx = reverse(fullnamegx);
  346.     lengx = length(fullnamegx);   /* get length of string */
  347.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  348.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  349.     seploc = 0; /* assumes current dir, no path supplied */
  350.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  351.       seploc = (lengx - slashdex)+1;
  352.       end;
  353.     else do
  354.       if colondex ~= 0 then do /* we assume we are on a device */
  355.         seploc = (lengx - colondex)+1;
  356.         end;
  357.       end;
  358.   extpos = lastpos(fullnamegx,'.');
  359.   if extpos > seploc then do
  360.     gxext = substr(fullnamegx,extpos+1);
  361.     end
  362.   else do
  363.     gxext = '';
  364.     end
  365.   return(gxext);
  366.   end
  367.  
  368.  
  369.